'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var React = _interopRequireWildcard(_react);

var _antd = require('antd');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

/**
 * 文本输入框提示字符
 * @author: cly
 * @since: 2019-10-14
 */
var TextArea = _antd.Input.TextArea;

var TextAreaTips = function (_React$Component) {
    (0, _inherits3['default'])(TextAreaTips, _React$Component);

    function TextAreaTips(props) {
        (0, _classCallCheck3['default'])(this, TextAreaTips);

        var _this = (0, _possibleConstructorReturn3['default'])(this, (TextAreaTips.__proto__ || Object.getPrototypeOf(TextAreaTips)).call(this, props));

        _this.state = {
            descCount: 0
        };
        _this.componentDidMount = function () {
            if (_this.ta.textAreaRef.innerHTML) {
                _this.wordStatic(_this.ta.textAreaRef.innerHTML);
            }
        };
        _this.wordStatic = function (value) {
            var onChange = _this.props.onChange;

            value = value || '';
            if (onChange) {
                onChange(value);
            }
            _this.setState({
                descCount: value.length
            });
        };
        return _this;
    }

    (0, _createClass3['default'])(TextAreaTips, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                maxLength = _props.maxLength,
                width = _props.width;
            var descCount = this.state.descCount;

            return React.createElement(
                'div',
                { style: { position: "relative", width: width } },
                React.createElement(TextArea, (0, _extends3['default'])({}, this.props, { onChange: function onChange(e) {
                        return _this2.wordStatic(e.target.value);
                    }, ref: function ref(r) {
                        _this2.ta = r;
                    } })),
                React.createElement(
                    'div',
                    { className: 'textareaCounter' },
                    React.createElement(
                        'span',
                        { id: 'num' },
                        descCount
                    ),
                    '/',
                    maxLength,
                    '\u5B57\u7B26'
                )
            );
        }
    }]);
    return TextAreaTips;
}(React.Component);

exports['default'] = TextAreaTips;
module.exports = exports['default'];